<?php
/**
 * Created by PhpStorm.
 * User: 冯轲
 * Date: 2017-11-14
 * Time: 10:07
 */
namespace app\admin;
use think\Controller;
use think\Hook;
use think\Request;
use think\Session;

class AdminCommon extends Controller{
    //控制器初始化,判断是否存在session
    public function _initialize()
    {
        $request=request();
        $re=Session::get('username');
        if($re==null){
            $this->error('请登录！','/login');
        }
        $rolelist=Session::get('rolelist');
        $controller=strtolower($request->controller());
        $action=($request->action());
       //echo '控制器:'.$controller.'----方法:'.$action;
     // print_r($rolelist);

        if(empty($rolelist[$controller]) || !in_array($action,$rolelist[$controller])){
            $this->error('抱歉，您无权操作，请联系管理员','/admin/index','控制器:'.$controller.'----方法:'.$action);
//            return '<script>alert(1)</script>';
        }

    }



}